home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-1.iso / games / ted5.zip / IGRABSRC.ZIP / XMS.C < prev    next >
C/C++ Source or Header  |  1993-02-04  |  3KB  |  172 lines

  1. ////////////////////////////////////////////////////
  2. //
  3. // XMS routines
  4. //
  5. ////////////////////////////////////////////////////
  6. #include "igrab.h"
  7. #pragma hdrstop
  8.  
  9.  
  10. unsigned XMSavail;
  11. void far *XMSdriver;
  12.  
  13.  
  14. ////////////////////////////////////////////////////
  15. //
  16. // Initialize the XMS memory
  17. //
  18. ////////////////////////////////////////////////////
  19. int InitXMS(void)
  20. {
  21.  //
  22.  // See if XMS driver is present...
  23.  //
  24.  asm    mov    ax,0x4300
  25.  asm    int    0x2f
  26.  asm    cmp    al,0x80        // installed?
  27.  asm    je    Present
  28.  
  29.  return -1;
  30.  
  31.  //
  32.  // YES! We found an XMS driver! Now we
  33.  // need to get the XMS driver's entry address...
  34.  //
  35.  Present:
  36.  asm    mov    ax,0x4310
  37.  asm    int    0x2f
  38.  asm    mov    WORD PTR XMSdriver,bx
  39.  asm    mov    WORD PTR XMSdriver+2,es
  40.  
  41.  return 0;
  42. }
  43.  
  44.  
  45. ////////////////////////////////////////////////////
  46. //
  47. // Report an XMS error, if any
  48. //
  49. ////////////////////////////////////////////////////
  50. void Quit(char *string)
  51. {
  52.  _AX=3;
  53.  geninterrupt(0x10);
  54.  printf("XMS ERROR: %s\n",string);
  55.  exit(1);
  56. }
  57.  
  58. void XMSerror(void)
  59. {
  60.  if (_AX==0)
  61.    switch(_BL)
  62.    {
  63.     case 0xa0: Quit("Not enough Extended Memory available!");
  64.     case 0xa7: Quit("Invalid length!");
  65.     case 0xa2: Quit("Invalid handle!");
  66.     case 0xa3:
  67.     case 0xa4:
  68.     case 0xa5:
  69.     case 0xa6: Quit("Invalid source or dest handle/offset!");
  70.     default: Quit("Unknown XMS Memory Error!");
  71.    }
  72. }
  73.  
  74. ////////////////////////////////////////////////////
  75. //
  76. // Allocate XMS memory
  77. //
  78. ////////////////////////////////////////////////////
  79. int XMSAllocate(long size)
  80. {
  81.  unsigned rdx=(size+1023)/1024;
  82.  
  83.  asm    mov    dx,[rdx]
  84.  asm    mov    ah,9
  85.  asm    call    [ss:DWORD PTR XMSdriver]
  86.  
  87.  XMSerror();
  88.  return _DX;
  89. }
  90.  
  91. ////////////////////////////////////////////////////
  92. //
  93. // Free XMS memory
  94. //
  95. ////////////////////////////////////////////////////
  96. void XMSFreeMem(int handle)
  97. {
  98.  asm    mov  dx,[handle]
  99.  asm    mov  ah,10
  100.  asm    call [DWORD PTR XMSdriver]
  101.  XMSerror();
  102. }
  103.  
  104.  
  105. ////////////////////////////////////////////////////
  106. //
  107. // Return XMS memory available
  108. //
  109. ////////////////////////////////////////////////////
  110. unsigned XMSTotalFree(void)
  111. {
  112.  asm    mov ah,8
  113.  asm    call [DWORD PTR XMSdriver]
  114.  if (!_AX && _BL!=0xa0)
  115.    XMSerror();
  116.  XMSavail=_DX;
  117.  return XMSavail;
  118. }
  119.  
  120. ////////////////////////////////////////////////////
  121. //
  122. // Move XMS memory
  123. //
  124. ////////////////////////////////////////////////////
  125. struct { long bsize;
  126.      int shandle;
  127.      long soff;
  128.      int dhandle;
  129.      long doff;
  130.        } XMSparms;
  131.  
  132.  
  133. void XMSmove(int srchandle,long srcoff,int desthandle,long destoff,long size)
  134. {
  135.  unsigned DSreg,SIreg;
  136.  
  137.  //
  138.  // FOR SOME FUCKING REASON, THE NEW MS-DOS 5.0
  139.  // HIMEM.SYS DRIVER DOESN'T ACCEPT ODD XMSMOVE LENGTHS!!!
  140.  // JOHN & I SPENT 5.5 HOURS DEBUGGING THIS BULLSHIT!!
  141.  // ---- FUCK YOU MICROSOFT!!! ---- (ASSHOLES!)
  142.  //
  143.  XMSparms.bsize=(size+1)&~1;
  144.  XMSparms.shandle=srchandle;
  145.  XMSparms.dhandle=desthandle;
  146.  XMSparms.soff=srcoff;
  147.  XMSparms.doff=destoff;
  148.  
  149.  DSreg=FP_SEG(&XMSparms);
  150.  SIreg=FP_OFF(&XMSparms);
  151.  
  152.  asm    mov    si,SIreg
  153.  asm    mov    ds,DSreg
  154.  
  155.  asm    mov    ah,11
  156.  asm    call    [ss:DWORD PTR XMSdriver]
  157.  
  158.  XMSerror();
  159. }
  160.  
  161.  
  162. ////////////////////////////////////////////////////
  163. //
  164. // XMS information
  165. //
  166. ////////////////////////////////////////////////////
  167. void XMSHandleInfo(int handle)
  168. {
  169.  asm    mov   dx,[handle]
  170.  asm    mov   ah,0xe
  171.  asm    call  [DWORD PTR XMSdriver]
  172. }